package com.gz.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class RabbitMQConfig {

    @Value("${rabbitmq.exchange-name}")
    String EX_CHANGE_NAME;

    @Value("${rabbitmq.queue}")
    String QUEUE_NAME;

    //配置交换机
    @Bean
    public TopicExchange initExchange() {
        return new TopicExchange(EX_CHANGE_NAME);
    }

    @Bean
    public DirectExchange exchangeTTL() {
        return new DirectExchange("TTL_Exchange");
    }

    //配置队列
    @Bean
    public Queue createQueue() {
        return new Queue(QUEUE_NAME);
    }

    @Bean
    public Queue queueTTL() {

        return new Queue("queue_ttl");
    }

    //交换机绑定队列
    @Bean
    public Binding initBinding() {
        return BindingBuilder.bind(createQueue()).to(initExchange()).with("item.boot");
    }

    @Bean
    public Binding ttlBinding() {
        return BindingBuilder.bind(queueTTL()).to(exchangeTTL()).with("ttl");
    }
}
